package com.topscore.uke.mvp.presenters;

import com.topscore.uke.entities.ProductDetailBean;
import com.topscore.uke.mvp.contractors.GetProductDetailContractor;
import com.topscore.uke.mvp.model.GetProductDetailModel;
import com.topscore.uke.network.BaseResponse;

public class GetProductDetailPresenter implements GetProductDetailContractor.Presenter, GetProductDetailContractor {
    private Model mModel;
    private View mView;
    private String mProductId;

    public GetProductDetailPresenter(String productId, View view) {
        this.mView = view;
        this.mProductId = productId;
        this.mModel = new GetProductDetailModel(new Model.CallBack() {
            @Override
            public void onSuccess(BaseResponse<ProductDetailBean> response) {
                mView.onGetDetailSuccess(response.getData());
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                mView.onFail(errorCode, errorMessage);
            }

            @Override
            public void onComplete() {
                mView.onLoadFinished();
            }
        });
    }

    @Override
    public void getProductDetail() {
        mView.onLoading("");
        mModel.getDetail(mProductId);
    }
}
